﻿using System.Data;
using PPWMS.Model;
using PPWMS.Log;
using System;
namespace PPWMS.BLL
{
    /// <summary>
    /// 系统菜单管理。
    /// </summary>
    public class SysManage
    {
        PPWMS.DAL.SysManage dal = new PPWMS.DAL.SysManage();
        private PPWMS.Log.Logmanagement log = new Logmanagement();

        public SysManage() { }

        public int AddTreeNode(SysNodeModel node)
        {
            try
            {
                return dal.AddTreeNode(node);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
                return -1;
            }
        }

        public void UpdateNode(SysNodeModel node)
        {
            try
            {
                dal.UpdateNode(node);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
        }

        public void DelTreeNode(int nodeid)
        {
            try
            {
                dal.DelTreeNode(nodeid);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
        }

        public DataSet GetTreeList(string strWhere)
        {
            try
            {
                return dal.GetTreeList(strWhere);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
                return null;
            }
        }

        public SysNodeModel GetNode(int NodeID)
        {
            try
            {
                return dal.GetNode(NodeID);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
                return null;
            }
        }

        public int GetPermissionCatalogID(int permissionID)
        {
            try
            {
                return dal.GetPermissionCatalogID(permissionID);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
                return -1;
            }
        }

        #region 日志管理
        public void AddLog(string time, string loginfo, string Particular)
        {
            try
            {
                dal.AddLog(time, loginfo, Particular);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
        }
        public void DelOverdueLog(int days)
        {
            try
            {
                dal.DelOverdueLog(days);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
        }
        public void DeleteLog(string Idlist)
        {
            string str = "";
            try
            {
                if (Idlist.Trim() != "")
                {
                    str = " ID in (" + Idlist + ")";
                }
                dal.DeleteLog(str);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
        }
        public void DeleteLog(string timestart, string timeend)
        {
            string str = " datetime>'" + timestart + "' and datetime<'" + timeend + "'";
            try
            {
                dal.DeleteLog(str);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
        }
        public DataSet GetLogs(string strWhere)
        {
            try
            {
                return dal.GetLogs(strWhere);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
                return null;
            }
        }
        public DataRow GetLog(string ID)
        {
            try
            {
                return dal.GetLog(ID);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
                return null;
            }
        }

        #endregion


    }
}
